package com.zhr.tea.view.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhr.tea.R;
import com.zhr.tea.entity.shouye.chayi.Chayi;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ym on 2016/11/4.
 */

public class ChayiAdapter extends RecyclerView.Adapter<ChayiAdapter.ChaViewHolder> implements View.OnClickListener{

    private List<Chayi.TeaDoctorListBean> data;
    private Context context;
    private RecycleListen listen=null;
    public ChayiAdapter(Context context, List<Chayi.TeaDoctorListBean> data,RecycleListen listen) {
        this.context = context;
        this.data = data;
        this.listen=listen;
    }

    @Override
    public void onClick(View view) {
        listen.listen(view, (Integer) view.getTag());
    }

    public interface RecycleListen{
        void listen(View view, int position);
    }
    @Override
    public ChaViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_chayi_recycle, null);
        ChaViewHolder holder = new ChaViewHolder(view);
        view.setOnClickListener(this);
        return holder;
    }

    @Override
    public void onBindViewHolder(final ChaViewHolder holder, final int position) {
        Glide.with(context).load(data.get(position).getCoverUrl()).placeholder(R.mipmap.diy_bg).into(holder.ivCover);
        holder.tvTitle.setText(data.get(position).getArticleTitle());
        holder.tvDescribe.setText(data.get(position).getArticleDescribe());
        holder.tvViewcount.setText(data.get(position).getViewsCount());
        holder.itemView.setTag(position);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class ChaViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_cover)
        ImageView ivCover;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_describe)
        TextView tvDescribe;
        @BindView(R.id.tv_viewcount)
        TextView tvViewcount;
        @BindView(R.id.iv_guanzhu)
        CheckBox ivGuanzhu;
        public ChaViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
